package ajk;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.BattlefieldSpecification;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that WallSpin moves to the center as specified when its hit by a bullet.
 * 
 * @author Anthony Kinsey
 * 
 */
public class TestWallSpinCenterMovement extends RobotTestBed {
  /** True if the robot visited the center during the test case. */
  boolean visitedCenter = false;

  BattlefieldSpecification b = new BattlefieldSpecification();

  /**
   * Specifies that Walls and WallSpin are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Walls,ajk.WallSpin";
  }

  /**
   * This test runs for 1 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * After each turn, check to see if we're at the center If so, set the corresponding flag.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double xPos = robot.getX();
    double yPos = robot.getY();
    double middleX = b.getWidth() / 2.0;
    double middleY = b.getHeight() / 2.0;
    // Checks to see if the robot visited the vicinity of the center
    if ((xPos < middleX + 50 && xPos > middleX - 50)
        && (yPos < middleY + 50 && yPos > middleY - 50)) {
      visitedCenter = true;
    }

  }

  /**
   * After the battle, check to see that we've visited the corners.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Center", visitedCenter);

  }

}
